sap.ui.define([
    "sap/ui/core/mvc/Controller",
    'sap/ui/comp/smartvariants/PersonalizableInfo',
    'sap/ui/model/Filter',
    'sap/ui/model/FilterOperator'
],
    /**
     * @param {typeof sap.ui.core.mvc.Controller} Controller
     */
    function (Controller, PersonalizableInfo, Filter, FilterOperator) {
        "use strict";

        return Controller.extend("ikdproject340.controller.FirstMain", {
            onInit: function () {
                this.oSmartVariantManagement = this.getView().byId("svm");
                this.oExpandedLabel = this.getView().byId("expandedLabel");
                this.oSnappedLabel = this.getView().byId("snappedLabel");
                this.oFilterBar = this.getView().byId("filterbar");
                this.oTable = this.getView().byId("MainTable");

                this.oFilterBar.registerGetFiltersWithValues(this.getFiltersWithValues);
                var oPersInfo = new PersonalizableInfo({
                    type: "filterBar",
                    keyName: "persistencyKey",
                    dataSource: "",
                    control: this.oFilterBar
                });
                this.oSmartVariantManagement.addPersonalizableControl(oPersInfo);
                this.oSmartVariantManagement.initialise(function () { }, this.oFilterBar);





            },
            onExit: function () {
                this.oModel = null;
                this.oSmartVariantManagement = null;
                this.oExpandedLabel = null;
                this.oSnappedLabel = null;
                this.oFilterBar = null;
                this.oTable = null;
            },
            getFiltersWithValues: function () {

                var aFiltersWithValue = this.oFilterBar.getFilterGroupItems().reduce(function (aResult, oFilterGroupItem) {
                    var oControl = oFilterGroupItem.getControl();

                    if (oControl && oControl.getSelectedKeys && oControl.getSelectedKeys().length > 0) {
                        aResult.push(oFilterGroupItem);
                    }

                    return aResult;
                }, []);


                return aFiltersWithValue;
            },
            onSelectionChange: function (oEvent) {
                // debugger
                this.oSmartVariantManagement.currentVariantSetModified(true);
                this.oFilterBar.fireFilterChange(oEvent);
            },
            onPressItem: function (oEvent) {
                // var oGlobalBusyDialog = new sap.m.BusyDialog();
                // oGlobalBusyDialog.open();

                var Cargmtno = oEvent.getSource().getBindingContext().getProperty("Cargmtno");

                var oCrossAppNavigator = sap.ushell.Container.getService("CrossApplicationNavigation"); // get a handle on the global XAppNav service
                
                var hash = (oCrossAppNavigator && oCrossAppNavigator.hrefForExternal({
                    target: {
                        semanticObject: "YMOON_DEV",
                        action: "Display2"
                    },
                    params: {
                        "Cargmtno": Cargmtno
                    }
                })) || ""; // generate the Hash to display a Supplier

                oCrossAppNavigator.toExternal({
                    target: {
                        shellHash: hash
                    }
                }); // navigate to Supplier application
            }
            // console.log("List sOrderId:========" + uuid)
            // var oRouter = this.getOwnerComponent().getRouter();
            // console.log(oEvent.getSource().getBindingContext().sPath)
            // var sPath = oEvent.getSource().getBindingContext().sPath;
            // console.log("sPath-------------",sPath)
            // oRouter.navTo("RouteDetail", { Uuid: uuid });
            // oRouter.navTo("SalesOrderDetail1", { orderId: sPath });
            // oRouter.navTo("SalesOrderDetail1", { orderId: window.encodeURIComponent(sPath) });
        
        });
    });
